<?php

namespace App\Http\Controllers;

use App\Http\Services\SmsService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

class SmsController extends BaseController
{
    public function index(Request $request)
    {
        $param = $this->validate($request,[
            'phone' => 'required',
            'tml' => 'required|in:1,2,3,4,5,6,7,8,9,10,11,12,13,14,15'
        ]);

        $templateCode = '';
        $code = mt_rand(100000,999999);
        $templateParam = [
            'code'  => $code
        ];

        Cache::put($param['phone'],$code,600);
        switch ($param['tml']){
            case 1:
                $templateCode = 'SMS_465362107';//登录
                break;
            case 2:
                $templateCode = 'SMS_465347153';//个人实名认证
                break;
            case 3:
                $templateCode = 'SMS_465322157';// 企业实名认证
                break;
            case 4:
                $templateCode = 'SMS_465327127'; // 企业入驻
                break;
            case 5:
                $templateCode = 'SMS_465317187';// 商协会入驻
                break;
            case 6:
                $templateCode = 'SMS_465322159'; // 我要开店
                break;
            case 7:
                $templateCode = 'SMS_465392145';// 申请顾问
                break;
            case 8:
                $templateCode = 'SMS_465392146';// 讲师合作
                break;
            case 9:
                $templateCode = 'SMS_465317188';//名人堂名人
                break;
            case 10:
                $templateCode = 'SMS_465372153'; // 创建圈子
                break;
            case 11:
                $templateCode = 'SMS_465352085'; // 企业猎才
                break;
            case 12:
                $templateCode = 'SMS_465317190';// 精英求职
                break;
            case 13:
                $templateCode = 'SMS_465337055'; // 会员卡购买
                break;
            case 14:
                $templateCode = '20041332953';
                break;
            case 15 :
                $templateCode = 'SMS_481750056';
                break;
        }


       $result = SmsService::send($templateCode,$param['phone'],$templateParam);
        return $result ? $this->success('发送成功') : $this->error('发送失败');
    }
}
